<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>大分类列表</title>
</head>

<body>
<div style="width:100%">

    <!--{include file='comm/menu.tpl'}-->
	<div class="search-box">
        <div style="position:relative">
            <form id="search_form" onsubmit="return false;">
                <table>
                    <tbody>
                    <tr>
                        <td height="27px">
                            大分类名称：<input type="text" id="categoryName" name="categoryName" value="" />
                            <input type="button" value="查询" class="btn" onclick="category.search();" />
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
    <table id="flex" style="display:none;"></table>

    <!--{include file='comm/footer.tpl'}-->

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/goods/category.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 140, align: "center"},
            {display: "大分类号", name : "bigCategoryID", width : 90, sortable : true},
            {display: "大分类名称", width : 330},
            {display: "分类类型", width : 90, align: "center"},
            {display: "使用状态", width : 90 , align: "center"},
            {display: "排序", width : 90, align: "center"}
        ],
        buttons : [
        	{name: "添加", bclass: "add", onpress : "category.add"},
            {separator: true}, //按钮之间的分割线
            {name: "删除", bclass: "delete", onpress : "category.delete"}
        ],
        sortname: "bigCategoryID",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,				//是否可以动态设置每页显示的结果数
        showTableToggleBtn: true,	//是否显示【显示隐藏Grid】的按钮
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var category = {

        delete_str: "" ,
		useFlg_str : "" ,
		
        //搜索分类
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },
		
        //添加分类
        add: function() {
            E.open("/quanliadmin/app/goods/goodsCategory.pscript?operFlg=2", "", {height: 600,width: 1024, top: 50, left: 150});
        },

        delete: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    category.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });
			
            if (this.delete_str == "")
                E.alert("请选择删除分类");
            else
                E.confirm("您确认要删除选中的分类吗？", "category.deleteConfirm");
        },
        
		doAction: function( categoryStr , useFlg ) {
            this.useFlg_str = categoryStr + "_" + useFlg ;
            if( useFlg == 0 )
            	E.confirm("您确认要禁用分类吗？", "category.actionConfirm");
            else
            	category.actionConfirm() ;
        },
        
        actionConfirm : function () {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/category.ajax?operFlg=5&useFlg_str=" + category.useFlg_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "category.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        
        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/category.ajax?operFlg=4&delete_str=" + category.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "category.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        edit: function(categoryID) {
            E.open("/quanliadmin/app/goods/goodsCategory.pscript?operFlg=3&categoryID=" + categoryID, "", {height: 600,width: 1024, top: 50, left: 150});
        },
        
        view : function(bigCategoryID){
        	 E.open("/quanliadmin/app/goods/goodsCategory.pscript?operFlg=4&bigCategoryID=" + bigCategoryID, "", {height: 600,width: 1024, top: 50, left: 150});
        },

        load: function() {
            $("#flex").flexReload();
        }

    };
</script>

</body>

</html>
